# -*- coding: utf-8 -*-
# @Time    : 2016-12-07 10:46
# @Author  : wzb<wangzhibin_x@foxmail.com>
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import csv
import pandas
import seaborn
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import math
from matplotlib.pyplot import MultipleLocator
import  re

filename='testdata/vol3.txt'
filename2='testdata/vol3_new.txt'

file=open(filename)
filenew =open(filename2,'w')
vol_v=0
i=0
for line in file:
    print(line)
    print('line len=%d'%len(line))
    if len(line)>2 and len(line)<60:
        if 'V' in line or 'v' in line:
            print(line)
            filenew.write(line.strip())
            vol_v=0
            i=0
    if len(line)>10:
        vol = re.findall(r'bms_vbat74v_adc_result=(.*)', line)
        if vol:
            strv=vol[0].strip()
            if len(strv)>5:
                print(strv)
                vol_v +=int(strv)
                i=i+1
                print('i=%d'%i)
                if i==5:
                    print(vol_v/5)
                    strvol=str(vol_v/5)
                    filenew.write(strvol)
                    filenew.write('\n')

file.close()
filenew.close()










